package edu.fourtwelve.srlzd_data;

import java.io.Serializable;

/**
 *
 * @author Christopher C. Hunt
 */
public class PasswordVerificationData implements Serializable {

    private transient Object CHAR_SYNCH;
    private volatile String usrName;
    private byte[] salt;
    private byte[] nonce;
    private byte[] password;
    private int passLength;

    public final PasswordVerificationData copy(PasswordVerificationData data) {
        final PasswordVerificationData ret = new PasswordVerificationData(data.getUsrName());

        ret.setPassword(data.getPassword());
        ret.setNonce(data.getNonce());
        ret.setSalt(data.getSalt());
        
        return ret;
    }
    
    public PasswordVerificationData(String usrName) {
        CHAR_SYNCH = new Object();
        this.usrName = usrName;
    }
    
    public String getUsrName() {
        return usrName;
    }

    public byte[] getPassword() {
        synchronized (CHAR_SYNCH) {
            return this.password;
        }
    }

    public byte[] getSalt() {
        synchronized (CHAR_SYNCH) {
            return this.salt;
        }
    }

    public byte[] getNonce() {
        synchronized (CHAR_SYNCH) {
            return this.salt;
        }
    }

    public void setPassword(byte[] newCh) {
        synchronized (CHAR_SYNCH) {
            this.password = new byte[newCh.length];
            System.arraycopy(newCh, 0, this.password, 0, newCh.length);
            this.passLength = this.password.length;
        }
    }

    public void setSalt(byte[] newCh) {
        synchronized (CHAR_SYNCH) {
            this.salt = new byte[newCh.length];
            System.arraycopy(newCh, 0, this.salt, 0, newCh.length);
        }
    }

    public void setNonce(byte[] newCh) {
        synchronized (CHAR_SYNCH) {
            this.nonce = new byte[newCh.length];
            System.arraycopy(newCh, 0, this.nonce, 0, newCh.length);
        }
    }

    private void writeObject(java.io.ObjectOutputStream stream)
            throws java.io.IOException {
        stream.defaultWriteObject();
    }

    private void readObject(java.io.ObjectInputStream stream)
            throws java.io.IOException, ClassNotFoundException {
        stream.defaultReadObject();
        this.CHAR_SYNCH = new Object();
    }
}
